import Vue from 'vue'
import VueRouter from 'vue-router'
// import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
 {
   path:'/',
   redirect:'/login'
 },
  {
    path: '/login',
    name: 'login',
    component: ()=>import("../views/login.vue")
  },
  {
    path: '/homepage',
    name: 'homepage',
    component: ()=>import("../views/homepage/index.vue"),
    redirect:'/homepage/backstage',
    children:[
      {
        path: 'backstage',
        name: 'backstage',
        component: ()=>import("../views/homepage/backstage.vue"),
      },
      {
        path: 'album',
        name: 'album',
        component: ()=>import("../views/homepage/album.vue"),
      },
      {
        path: 'list',
        name: 'list',
        component: ()=>import("../views/homepage/list.vue"),
      }
    ]
  },
  {
    path: '/commodity',
    name: 'commodity',
    component: ()=>import("../views/commodity/index.vue"),
    redirect:'/commodity/Commoditylist',
    children:[
      {
        path: 'Commoditylist',
        name: 'Commoditylist',
        component: ()=>import("../views/commodity/Commoditylist.vue")
      },
      {
        path: 'Classificationlist',
        name: 'Classificationlist',
        component: ()=>import("../views/commodity/Classificationlist.vue")
      },
      {
        path: 'Commodityspecifications',
        name: 'Commodityspecifications',
        component: ()=>import("../views/commodity/Commodityspecifications.vue")
      },
      {
        path: 'Commoditytype',
        name: 'Commoditytype',
        component: ()=>import("../views/commodity/Commoditytype.vue")
      },
      {
        path: 'Productreviews',
        name: 'Productreviews',
        component: ()=>import("../views/commodity/Productreviews.vue")
      },
    ]
  },
  {
    path: '/member',
    name: 'member',
    component: ()=>import("../views/member/index.vue"),
    redirect:'/member/Membershiplist',
    children:[
      {
        path: 'Membershiplist',
        name: 'Membershiplist',
        component: ()=>import("../views/member/Membershiplist.vue")
      },
      {
        path: 'Membershiplevel',
        name: 'Membershiplevel',
        component: ()=>import("../views/member/Membershiplevel.vue")
      },
    ]
  },
  {
    path: '/order',
    name: 'order',
    component: ()=>import("../views/order/index.vue"),
    redirect:'/order/Ordermanagement',
    children:[
      {
        path: 'Ordermanagement',
        name: 'Ordermanagement',
        component: ()=>import("../views/order/Ordermanagement.vue")
      },
      {
        path: 'controloverinvoices',
        name: 'controloverinvoices',
        component: ()=>import("../views/order/controloverinvoices.vue")
      },
      {
        path: 'aftersaleservice',
        name: 'aftersaleservice',
        component: ()=>import("../views/order/aftersaleservice.vue")
      },
    ]
  },
  {
    path: '/setup',
    name: 'setup',
    component: ()=>import("../views/setup/index.vue"),
    redirect:'/setup/Basicsettings',
    children:[
      {
        path: 'Basicsettings',
        name: 'Basicsettings',
        component: ()=>import("../views/setup/Basicsettings.vue")
      },
      {
        path: 'Logisticssettings',
        name: 'Logisticssettings',
        component: ()=>import("../views/setup/Logisticssettings.vue")
      },
      {
        path: 'Administratorsettings',
        name: 'Administratorsettings',
        component: ()=>import("../views/setup/Administratorsettings.vue")
      },
      {
        path: 'Transactionsetup',
        name: 'Transactionsetup',
        component: ()=>import("../views/setup/Transactionsetup.vue")
      },
    ]
  },

  // {
  //   path: '/about',
  //   name: 'About',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  // }
]

const router = new VueRouter({
  routes
})


router.beforeEach((to, from, next) => {
  console.log(to.path);
  if (localStorage.getItem("token")) {
      next();
      //如果已经登陆了就该怎么执行怎么执行
  } else {
      if (to.path == "/login") {
          next();
      } else {
          next("/login");
      }
  }
});

//全局的路由守卫 守卫所有的跳转，如果已经登陆了就正常执行跳转
// 如果没有登陆就跳转到登陆页面 会有一个死循环 所以要判断是否是登陆页面 如果是登陆页面就继续

export default router
